package org.judo.utility;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class FileSearcher
{
	String fileName;
	
	public FileSearcher(String start,String pattern) throws Exception
	{
		findFileWithContentPattern(new File(start),pattern);
	}
	
	public void findFileWithContentPattern(File root,String pattern)
		throws Exception
	{
		File files[] = root.listFiles();
		
		for (File file:files)
		{
			if (file.isDirectory())
				findFileWithContentPattern(file,pattern);
			else
			{
				BufferedReader br
					= new BufferedReader(new FileReader(file));
				
				String line = br.readLine();
				
				while (line != null)
				{
					if (line.contains(pattern))
					{
						fileName = file.getAbsolutePath();
					}
					
					line = br.readLine();
				}
				
				br.close();
			}
		}
	}

	public String getFileName()
	{
		return fileName;
	}

	public void setFileName(String fileName)
	{
		this.fileName = fileName;
	}

}